<?php

include_once "docgeral.class.php";

class DocGeralModelo extends DocGeral {
    
    var $db;

    //Conectar ao banco de dados passando o Login do DB como parâmetro
    function DocGeralModelo() {
            $db = "campusseguro";

            $this->db = new DataBase($db);
    }

    function insert() {
        $query = sprintf("INSERT INTO docgeral (type, number, name, flag) VALUES('%s', '%s', '%s', '%s')", $this->getType(), $this->getNumber(), $this->getName(), $this->getFlag());
        $rs = mysql_query($query, $this->db->connection) or die(mysql_error());
        if(!$rs) {
            return false;
        }
        return true;
    }
    
    function updateType() {
        $query = sprintf("UPDATE docgeral SET type='%s' WHERE id='%s'", $this->getType(), $this->getId());
        $rs = mysql_query($query, $this->db->connection);
        if(!$rs) {
            return false;
        }
        return true;
    }
    
	function updateNumber() {
        $query = sprintf("UPDATE docgeral SET number='%s' WHERE id='%s'", $this->getNumber(), $this->getId());
        $rs = mysql_query($query, $this->db->connection);
        if(!$rs) {
            return false;
        }
        return true;
    }
	function updateName() {
        $query = sprintf("UPDATE docgeral SET name='%s' WHERE id='%s'", $this->getName(), $this->getId());
        $rs = mysql_query($query, $this->db->connection);
        if(!$rs) {
            return false;
        }
        return true;
    }
	
	function updateFlag() {
        $query = sprintf("UPDATE docgeral SET flag='%s' WHERE id='%s'", $this->getFlag(), $this->getId());
        $rs = mysql_query($query, $this->db->connection);
        if(!$rs) {
            return false;
        }
        return true;
    }
	
    function delete() {
        $query = sprintf("DELETE FROM docgeral WHERE id = '%s'", $this->getId());
        $rs = mysql_query($query, $this->db->connection);
        if(!$rs) {
            return false;
        }
        return true;
    }
    
    function select($comp) {
        $selectQuery = sprintf("SELECT * FROM docgeral ".$comp);
        $rs = mysql_query($selectQuery, $this->db->connection);
        $arrayResultado = array();
        $i = 0;
        while($resultado = mysql_fetch_assoc($rs)) {
            $arrayResultado[$i]['id'] = $resultado['id'];
            $arrayResultado[$i]['type'] = $resultado['type'];
            $arrayResultado[$i]['number'] = $resultado['number'];
			$arrayResultado[$i]['name'] = $resultado['name'];
			$arrayResultado[$i]['flag'] = $resultado['flag'];	
			$i++;
        }
        return $arrayResultado;
    }
    
}

?>
